package yxy.game.pm2.module.plainsCraft;

import org.joda.time.DateTime;
import yxy.game.pm2.bean.module.rank.IWorshipableRank;
import yxy.game.pm2.bean.module.rank.PlayerRankModule;
import yxy.game.pm2.bean.module.rank.RankModule;
import yxy.game.pm2.bean.module.rank.RankWorship;

//中原争霸，段位排行榜
public class RankPlainsCraft extends RankModule implements IWorshipableRank {
	private int areaGroupId; //战区id，按战区排名
	private int level;// 段位
	private RankWorship worship;

	public int getAreaGroupId() {
		return areaGroupId;
	}

	public void setAreaGroupId(int areaGroupId) {
		this.areaGroupId = areaGroupId;
	}

	public RankPlainsCraft(int areaGroupId, int level) {
		this.level = level;
		setAreaGroupId(areaGroupId);
		initInfo();
		worship = new RankWorship(rankKey(), rankName());
	}

	@Override
	public RankWorship getWorship() {
		return worship;
	}

	@Override
	public String rankName() {
		return PlayerRankModule.getAllRankNames().get(6);
	}

	@Override
	protected long valuePlastic(long value) {
		return -value;
	}

	@Override
	protected long valueRestore(long score) {
		return -score;
	}

	@Override
	protected String rankKey() {
		return String.format("WORLD:%s:RANK:PLAINSCRAFT:%s", getAreaGroupId(), level);
	}

	public void put(String playerCode) {
		super.put(playerCode, DateTime.now().getMillis());
	}

	/** 替换数据 */
	public void put(String key, long value) {
		try {
			if (tryLock()) {
				long v = valuePlastic(value);
				touch().add(v, key);
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			unlock();
		}
	}

}
